﻿namespace JsViewEngine
{
    using System.Web;

    public static class JsTemplates
    {
        private static HttpContextBase context;

        internal static HttpContextBase Context
        {
            get
            {
                return JsTemplates.context ?? (HttpContextBase)new HttpContextWrapper(HttpContext.Current);
            }
            set
            {
                JsTemplates.context = value;
            }
        }

        private static JsTemplateManager Manager
        {
            get { return JsTemplateManager.GetInstance(Context); }
        }

        public static IHtmlString RenderTemplateBlock(params string[] names)
        {
            return Manager.Render(names);
        }

        public static IHtmlString ObjectToJson(object value)
        {
            return new HtmlString(Newtonsoft.Json.JsonConvert.SerializeObject(value));
        }

        public static IHtmlString RenderTemplateString(string name)
        {
            return Manager.RenderJsString(name);
        }
    }
}